import mysql from 'mysql2/promise';

const config = useRuntimeConfig();
// 创建数据库连接池
const pool = mysql.createPool({
  host: config.DB_HOST || 'localhost',
  user: config.DB_USER || 'root',
  password: config.DB_PASSWORD || '',
  database: config.DB_NAME || 'nuxt3_db',
  port: Number(config.DB_PORT) || 3306,
  waitForConnections: true, // 连接池满时等待
  connectionLimit: 100, // 最大连接数
  queueLimit: 0, // 无限制排队
  idleTimeout: 30000, // 连接空闲超时时间(ms)
});

export default pool;